import React from "react";
import { inject , observer } from 'mobx-react';
import { Modal } from "antd";
import {toJS}from 'mobx';
import { WeaTools, WeaDialog, WeaLocaleProvider } from 'ecCom';


const getLabel = WeaLocaleProvider.getLabel;

@observer
export default class GroupDialog extends React.Component {
    constructor(props) {
        super(props);
        const {addGroupModalVisible}=this.props.wfForwardStore;
    }

    render() {
        // const { dataParams = {} } = this.props;
        const { ops,groupId,groupType,addGroupModalVisible, setOptParams, controllAddModal, loadHrmGroupData } = this.props.wfForwardStore;
        // const { groupType, groupId, visible = false, ops } = optParams;
        let dialogProps = {
            icon:"icon-coms-workflow",
            iconBgcolor:'#0079DE',
            visible:addGroupModalVisible,
        };
        const cancelHandler = () =>{controllAddModal(false); setOptParams({ops:"",groupId:"",groupType:"",addGroupModalVisible:false})};
        if (ops == "advice") {
            const adviceGroupUrl = `/spa/hrm/static/index.html#/main/hrm/groupAdvice?groupId=${groupId}`;
            // 公共组调整建议弹框
            dialogProps = {
                ...dialogProps,
                title: getLabel("126253", "公共组调整建议"),
                style: { width: 650, height: 360 },
                url: adviceGroupUrl,
                onCancel: cancelHandler,
                callback: cancelHandler
            };
        } else if (ops == "add" || ops == "edit") {
            const fId = "";
            // const fId = dataParams.f_weaver_belongto_userid || "";
            const createGroupUrl = `/spa/hrm/index_mobx.html#/main/hrm/operateGroup?groupType=${groupType}`;
            const editGroupUrl = `/spa/hrm/index_mobx.html#/main/hrm/operateGroup?groupId=${groupId}`;
            let groupUrl = ops == "add" ? createGroupUrl : editGroupUrl;
            if (fId) groupUrl += `&f_weaver_belongto_userid=${fId}`;
            console.log("dialogProps",toJS(dialogProps))
            // 新建 编辑常用组弹框
            dialogProps = {
                ...dialogProps,
                title:
                    ops == "add"
                        ? getLabel("386496", "新建常用组")
                        : getLabel("126252", "常用组设置"),
                style:
                    ops == "add"
                        ? { width: 650, height: 225 }
                        : { width: 750, height: 482 },
                url: groupUrl,
                onCancel: ()=>{controllAddModal(false)},
                callback: type =>{
                    let optParams={}
                    if(type){
                        optParams= { groupId:dialogProps.groupId,groupType:dialogProps.groupType,addGroupModalVisible:dialogProps.visible, ops: "edit" } 
                    }else{
                        optParams= { groupId:"",groupType:"",addGroupModalVisible:false, ops: "" } 
                    }
                    loadHrmGroupData();
                    setOptParams(optParams)
                }

            };
        }
        return <WeaDialog ecId={`${this && this.props && this.props.ecId || ''}_WeaDialog@qpjrh4`} {...dialogProps} />;
    }

}



// WEBPACK FOOTER //
// ./ecology9/wea-browser-test/components/GroupDialog.js